// yb_shop/pages/book_info/index.js
var t = getApp(),
c = t.requirejs("api/index"),
  a = t.requirejs("core"),
s = t.requirejs("wxParse/wxParse");
var running = false;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show:false,
    //万能表单
    default_pic: '/yb_shop/static/images/add_pic.jpg',
    form: [],
    data: {}
  },
  //底部导航跳转
  menu_url: function (k) {
    a.menu_url(k, 2);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    var that=this;
    a.setting();
    that.setData(e);
    if(e.id){
      that.get_info();
    }else{
      a.alert('未获取到预约信息');
    }
  },
  get_info:function(){
    var that=this,
    id=that.data.id;
    a.get('Market/bookinfo', { id: id }, function (t) {
      if (t.code == 0) {
        that.setData({
          "item.param": t.info.form_id+""
        })
        c.get_form_list(3, t.info.form_id, that);
        s.wxParse("wxParseData", "html", t.info.content, that, "0");
        that.setData({
          info: t.info,
          show: true
        })
      } else {
        a.alert(t.msg);
      }
    })
  },
  // 万能表单提交begin//
  formPower: function (e) {
  
    var that=this,
      id = that.data.item.param+"",
      form = that.data.power_form[id].form,
        data = e.detail.value;
 var send_form_id = e.detail.formId;
      delete (data['id']);
      c.validate(data, form, function (k) {//字段验证
        if (k == 0) {

          data = JSON.stringify(c.to_str(data, form));//转换字段格式
          a.loading('正在提交中...');
          a.post('Market/submitbook', {
            data: data,
            form: JSON.stringify(form),
            thing_id: that.data.info.id,
            user_id: t.getCache("userinfo").uid
          }, function (t) {
            a.hideLoading();
            if (t.code == 0) {
              a.success('提交成功');
              
              var old_form = that.data.power_form;
              old_form[id].form = form;
              that.setData({
                power_form: old_form,
                form_data: {}
              })
              //消息推送
              c.send_news(send_form_id, that.data.info.id,'book');
            } else {
              a.alert(t.msg);
            }
          })
        } else {
          return;
        }
      });
  },
  bindPickerChange: function (e) {
    c.bindPickerChange(this, e);
  },
  listen_time_two: function (e) {
    c.listen_time_two(this, e);
  },
  chooseImageTap1: function (e) {
    var id = a.pdata(e).id;
    c.upload(this, id, 'book_pic', 1)
  },
  chooseImageTap2: function (e) {
    var id = a.pdata(e).id;
    c.upload(this, id, 'book_pic', 0)
  },
  Image_del: function (e) {
    c.Image_del(this, e);
  },
   // 万能表单提交end//
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})